package bhbt.controller.member.member;


import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import bhbt.controller.core.BaseController;
import bhbt.model.Member;
import bhbt.service.MemberService;
import bhbt.taglib.pagetag.Pagination;
import bhbt.utils.ContextUtil;
import bhbt.utils.MapUtil;






/**
 * Created by Administrator on 2016/3/25.
 */
@Controller

public class MemberListController extends BaseController {
    @Resource
    private MemberService memberService;
   
     

	/**
     * 未激活
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping("member/member/memberNoActiveList.shtml")
    public String memberNoActiveList(HttpServletRequest request) throws Exception{
        HashMap formMap = getParameterMap(request);
        Member member = ContextUtil.getMember();
        formMap.put("accountActive", "F");	//未激活
        
        //formMap.put("where", " a.accountActive == 'F'");	//  未激活
        formMap.put("where"," (a.recommendId="+member.getId()+" or a.registerId = "+member.getId()+" or a.centerId = "+member.getId()+" ) order by a.id desc ");
        
        Pagination page = memberService.queryForPageList("memberForPage",formMap);
       
        request.setAttribute(Pagination.pageBeanName, page);
   
        return "member/member/memberNoActiveList";
    }

     
    /**
     * 未激活删除
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping("member/member/memberNoActiveDelete.shtml")
    public String memberNoActiveDelete(HttpServletRequest request) throws Exception{
        Map formMap = getParameterMap(request);
        String loginName = MapUtil.getString(formMap, "loginName");
        //删除的会员
        Member one = memberService.executMemberByLoginName(loginName);
        //登陆的会员
        Member member = ContextUtil.getMember();
        if(one!=null){
        	if(one.getRecommendId()==member.getId()||one.getRegisterId()==member.getId()){
        		memberService.deleteOne(one.getId());
        	}
        	
        }
        
        
        return "redirect:memberNoActiveList.shtml";
       
    }
    
    
    
    /**
     * 已激活
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping("member/member/memberYesActiveList.shtml")
    public String memberYesActiveList(HttpServletRequest request) throws Exception{
        HashMap formMap = getParameterMap(request);
        Member member = ContextUtil.getMember();
        formMap.put("accountActive", "T");	//未激活
        formMap.put("where","(a.recommendId="+member.getId()+" or a.registerId = "+member.getId()+" or a.activeId = "+member.getId()+" ) order by a.activeDate desc ");
        
        Pagination page = memberService.queryForPageList("memberForPage",formMap);
       
        request.setAttribute(Pagination.pageBeanName, page);
        
   
        return "member/member/memberYesActiveList";
    }

     
}
